﻿using System.Text.RegularExpressions;

namespace CTP.CRM.Core.Helper
{

    /// <summary>
    /// 正则匹配
    /// </summary>
    public class RegexHelper
    {
        public static string TelRegEx { get; set; } = @"^(1)\d{10}$";

        public static bool IsValidTelphone(string telPhone)
        {
            if (string.IsNullOrEmpty(telPhone))
            {
                return false;
            }
            return Regex.IsMatch(telPhone, TelRegEx, RegexOptions.Compiled | RegexOptions.IgnoreCase);
        }

        /// <summary>
        /// 验证密码
        ///  /^(?=.*[a-z]|[A-Z])(?=.*\d)(?=.*[\W_]).{8,20}$/
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool IsValidPassword(string password)
        {
            // Check for length
            if (string.IsNullOrEmpty(password) || password.Length < 8 || password.Length > 20)
            {
                return false;
            }

            // Check for at least one digit, one letter, and one special character
            bool hasDigit = password.Any(char.IsDigit);
            bool hasLetter = password.Any(char.IsLetter);
            bool hasSpecialChar = password.Any(ch => !char.IsLetterOrDigit(ch));

            if (!hasDigit || !hasLetter || !hasSpecialChar)
            {
                return false;
            }

            return true;
        }
    }
}
